| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_H_ | 5 #ifndef APP_OS_EXCHANGE_DATA_H_ |
| 6 #define APP_OS_EXCHANGE_DATA_H_ | 6 #define APP_OS_EXCHANGE_DATA_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" |
| 9 |
| 10 #if defined(OS_WIN) |
| 8 #include <atlbase.h> | 11 #include <atlbase.h> |
| 9 #include <objidl.h> | 12 #include <objidl.h> |
| 13 #endif |
| 10 #include <vector> | 14 #include <vector> |
| 11 | 15 |
| 12 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 13 | 17 |
| 14 class GURL; | 18 class GURL; |
| 15 class Pickle; | 19 class Pickle; |
| 16 | 20 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 21 /////////////////////////////////////////////////////////////////////////////// |
| 18 // | 22 // |
| 19 // OSExchangeData | 23 // OSExchangeData |
| 20 // An object that holds interchange data to be sent out to OS services like | 24 // An object that holds interchange data to be sent out to OS services like |
| 21 // clipboard, drag and drop, etc. This object exposes an API that clients can | 25 // clipboard, drag and drop, etc. This object exposes an API that clients can |
| 22 // use to specify raw data and its high level type. This object takes care of | 26 // use to specify raw data and its high level type. This object takes care of |
| 23 // translating that into something the OS can understand. | 27 // translating that into something the OS can understand. |
| 24 // | 28 // |
| 25 /////////////////////////////////////////////////////////////////////////////// | 29 /////////////////////////////////////////////////////////////////////////////// |
| 30 #if defined(OS_WIN) |
| 26 class OSExchangeData : public IDataObject { | 31 class OSExchangeData : public IDataObject { |
| 32 #else |
| 33 class OSExchangeData { |
| 34 #endif |
| 27 public: | 35 public: |
| 36 #if defined(OS_WIN) |
| 28 // Returns true if source has plain text that is a valid url. | 37 // Returns true if source has plain text that is a valid url. |
| 29 static bool HasPlainTextURL(IDataObject* source); | 38 static bool HasPlainTextURL(IDataObject* source); |
| 30 | 39 |
| 31 // Returns true if source has plain text that is a valid URL and sets url to | 40 // Returns true if source has plain text that is a valid URL and sets url to |
| 32 // that url. | 41 // that url. |
| 33 static bool GetPlainTextURL(IDataObject* source, GURL* url); | 42 static bool GetPlainTextURL(IDataObject* source, GURL* url); |
| 34 | 43 |
| 44 explicit OSExchangeData(IDataObject* source); |
| 45 #endif |
| 46 |
| 35 OSExchangeData(); | 47 OSExchangeData(); |
| 36 OSExchangeData(IDataObject* source); | |
| 37 virtual ~OSExchangeData(); | 48 virtual ~OSExchangeData(); |
| 38 | 49 |
| 39 // These functions add data to the OSExchangeData object of various Chrome | 50 // These functions add data to the OSExchangeData object of various Chrome |
| 40 // types. The OSExchangeData object takes care of translating the data into | 51 // types. The OSExchangeData object takes care of translating the data into |
| 41 // a format suitable for exchange with the OS. | 52 // a format suitable for exchange with the OS. |
| 42 // NOTE WELL: Typically, a data object like this will contain only one of the | 53 // NOTE WELL: Typically, a data object like this will contain only one of the |
| 43 // following types of data. In cases where more data is held, the | 54 // following types of data. In cases where more data is held, the |
| 44 // order in which these functions are called is _important_! | 55 // order in which these functions are called is _important_! |
| 45 // ---> The order types are added to an OSExchangeData object controls | 56 // ---> The order types are added to an OSExchangeData object controls |
| 46 // the order of enumeration in our IEnumFORMATETC implementation! | 57 // the order of enumeration in our IEnumFORMATETC implementation! |
| 47 // This comes into play when selecting the best (most preferable) | 58 // This comes into play when selecting the best (most preferable) |
| 48 // data type for insertion into a DropTarget. | 59 // data type for insertion into a DropTarget. |
| 49 void SetString(const std::wstring& data); | 60 void SetString(const std::wstring& data); |
| 50 // A URL can have an optional title in some exchange formats. | 61 // A URL can have an optional title in some exchange formats. |
| 51 void SetURL(const GURL& url, const std::wstring& title); | 62 void SetURL(const GURL& url, const std::wstring& title); |
| 52 // A full path to a file | 63 // A full path to a file |
| 53 void SetFilename(const std::wstring& full_path); | 64 void SetFilename(const std::wstring& full_path); |
| 65 #if defined(OS_WIN) |
| 54 // Adds pickled data of the specified format. | 66 // Adds pickled data of the specified format. |
| 55 void SetPickledData(CLIPFORMAT format, const Pickle& data); | 67 void SetPickledData(CLIPFORMAT format, const Pickle& data); |
| 68 #endif |
| 56 // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR). | 69 // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR). |
| 57 void SetFileContents(const std::wstring& filename, | 70 void SetFileContents(const std::wstring& filename, |
| 58 const std::string& file_contents); | 71 const std::string& file_contents); |
| 59 // Adds a snippet of HTML. |html| is just raw html but this sets both | 72 // Adds a snippet of HTML. |html| is just raw html but this sets both |
| 60 // text/html and CF_HTML. | 73 // text/html and CF_HTML. |
| 61 void SetHtml(const std::wstring& html, const GURL& base_url); | 74 void SetHtml(const std::wstring& html, const GURL& base_url); |
| 62 | 75 |
| 63 // These functions retrieve data of the specified type. If data exists, the | 76 // These functions retrieve data of the specified type. If data exists, the |
| 64 // functions return and the result is in the out parameter. If the data does | 77 // functions return and the result is in the out parameter. If the data does |
| 65 // not exist, the out parameter is not touched. The out parameter cannot be | 78 // not exist, the out parameter is not touched. The out parameter cannot be |
| 66 // NULL. | 79 // NULL. |
| 67 bool GetString(std::wstring* data) const; | 80 bool GetString(std::wstring* data) const; |
| 68 bool GetURLAndTitle(GURL* url, std::wstring* title) const; | 81 bool GetURLAndTitle(GURL* url, std::wstring* title) const; |
| 69 // Return the path of a file, if available. | 82 // Return the path of a file, if available. |
| 70 bool GetFilename(std::wstring* full_path) const; | 83 bool GetFilename(std::wstring* full_path) const; |
| 84 #if defined(OS_WIN) |
| 71 bool GetPickledData(CLIPFORMAT format, Pickle* data) const; | 85 bool GetPickledData(CLIPFORMAT format, Pickle* data) const; |
| 86 #endif |
| 72 bool GetFileContents(std::wstring* filename, | 87 bool GetFileContents(std::wstring* filename, |
| 73 std::string* file_contents) const; | 88 std::string* file_contents) const; |
| 74 bool GetHtml(std::wstring* html, GURL* base_url) const; | 89 bool GetHtml(std::wstring* html, GURL* base_url) const; |
| 75 | 90 |
| 76 // Test whether or not data of certain types is present, without actually | 91 // Test whether or not data of certain types is present, without actually |
| 77 // returning anything. | 92 // returning anything. |
| 78 bool HasString() const; | 93 bool HasString() const; |
| 79 bool HasURL() const; | 94 bool HasURL() const; |
| 80 bool HasURLTitle() const; | 95 bool HasURLTitle() const; |
| 81 bool HasFile() const; | 96 bool HasFile() const; |
| 97 #if defined(OS_WIN) |
| 82 bool HasFormat(CLIPFORMAT format) const; | 98 bool HasFormat(CLIPFORMAT format) const; |
| 83 | 99 |
| 84 // IDataObject implementation: | 100 // IDataObject implementation: |
| 85 HRESULT __stdcall GetData(FORMATETC* format_etc, STGMEDIUM* medium); | 101 HRESULT __stdcall GetData(FORMATETC* format_etc, STGMEDIUM* medium); |
| 86 HRESULT __stdcall GetDataHere(FORMATETC* format_etc, STGMEDIUM* medium); | 102 HRESULT __stdcall GetDataHere(FORMATETC* format_etc, STGMEDIUM* medium); |
| 87 HRESULT __stdcall QueryGetData(FORMATETC* format_etc); | 103 HRESULT __stdcall QueryGetData(FORMATETC* format_etc); |
| 88 HRESULT __stdcall GetCanonicalFormatEtc( | 104 HRESULT __stdcall GetCanonicalFormatEtc( |
| 89 FORMATETC* format_etc, FORMATETC* result); | 105 FORMATETC* format_etc, FORMATETC* result); |
| 90 HRESULT __stdcall SetData( | 106 HRESULT __stdcall SetData( |
| 91 FORMATETC* format_etc, STGMEDIUM* medium, BOOL should_release); | 107 FORMATETC* format_etc, STGMEDIUM* medium, BOOL should_release); |
| 92 HRESULT __stdcall EnumFormatEtc( | 108 HRESULT __stdcall EnumFormatEtc( |
| 93 DWORD direction, IEnumFORMATETC** enumerator); | 109 DWORD direction, IEnumFORMATETC** enumerator); |
| 94 HRESULT __stdcall DAdvise( | 110 HRESULT __stdcall DAdvise( |
| 95 FORMATETC* format_etc, DWORD advf, IAdviseSink* sink, DWORD* connection); | 111 FORMATETC* format_etc, DWORD advf, IAdviseSink* sink, DWORD* connection); |
| 96 HRESULT __stdcall DUnadvise(DWORD connection); | 112 HRESULT __stdcall DUnadvise(DWORD connection); |
| 97 HRESULT __stdcall EnumDAdvise(IEnumSTATDATA** enumerator); | 113 HRESULT __stdcall EnumDAdvise(IEnumSTATDATA** enumerator); |
| 98 | 114 |
| 99 // IUnknown implementation: | 115 // IUnknown implementation: |
| 100 HRESULT __stdcall QueryInterface(const IID& iid, void** object); | 116 HRESULT __stdcall QueryInterface(const IID& iid, void** object); |
| 101 ULONG __stdcall AddRef(); | 117 ULONG __stdcall AddRef(); |
| 102 ULONG __stdcall Release(); | 118 ULONG __stdcall Release(); |
| 119 #endif |
| 103 | 120 |
| 104 private: | 121 private: |
| 122 #if defined(OS_WIN) |
| 105 // FormatEtcEnumerator only likes us for our StoredDataMap typedef. | 123 // FormatEtcEnumerator only likes us for our StoredDataMap typedef. |
| 106 friend class FormatEtcEnumerator; | 124 friend class FormatEtcEnumerator; |
| 107 | 125 |
| 108 // Our internal representation of stored data & type info. | 126 // Our internal representation of stored data & type info. |
| 109 struct StoredDataInfo { | 127 struct StoredDataInfo { |
| 110 FORMATETC format_etc; | 128 FORMATETC format_etc; |
| 111 STGMEDIUM* medium; | 129 STGMEDIUM* medium; |
| 112 bool owns_medium; | 130 bool owns_medium; |
| 113 | 131 |
| 114 StoredDataInfo(CLIPFORMAT cf, STGMEDIUM* a_medium) { | 132 StoredDataInfo(CLIPFORMAT cf, STGMEDIUM* a_medium) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 130 } | 148 } |
| 131 } | 149 } |
| 132 }; | 150 }; |
| 133 | 151 |
| 134 typedef std::vector<StoredDataInfo*> StoredData; | 152 typedef std::vector<StoredDataInfo*> StoredData; |
| 135 StoredData contents_; | 153 StoredData contents_; |
| 136 | 154 |
| 137 CComPtr<IDataObject> source_object_; | 155 CComPtr<IDataObject> source_object_; |
| 138 | 156 |
| 139 LONG ref_count_; | 157 LONG ref_count_; |
| 158 #endif |
| 140 | 159 |
| 141 DISALLOW_EVIL_CONSTRUCTORS(OSExchangeData); | 160 DISALLOW_COPY_AND_ASSIGN(OSExchangeData); |
| 142 }; | 161 }; |
| 143 | 162 |
| 144 #endif // #ifndef APP_OS_EXCHANGE_DATA_H_ | 163 #endif // #ifndef APP_OS_EXCHANGE_DATA_H_ |
| OLD | NEW |