| 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_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" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include <objidl.h> | 15 #include <objidl.h> |
| 16 #elif defined(OS_LINUX) | 16 #elif defined(OS_LINUX) |
| 17 #include <gtk/gtk.h> | 17 #include <gtk/gtk.h> |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
| 21 #include "base/file_path.h" |
| 22 #include "base/ref_counted.h" |
| 21 #include "base/scoped_ptr.h" | 23 #include "base/scoped_ptr.h" |
| 22 | 24 |
| 23 class GURL; | 25 class GURL; |
| 24 class Pickle; | 26 class Pickle; |
| 25 | 27 |
| 26 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
| 27 // | 29 // |
| 28 // OSExchangeData | 30 // OSExchangeData |
| 29 // An object that holds interchange data to be sent out to OS services like | 31 // An object that holds interchange data to be sent out to OS services like |
| 30 // clipboard, drag and drop, etc. This object exposes an API that clients can | 32 // clipboard, drag and drop, etc. This object exposes an API that clients can |
| (...skipping 21 matching lines...) Expand all Loading... |
| 52 STRING = 1 << 0, | 54 STRING = 1 << 0, |
| 53 URL = 1 << 1, | 55 URL = 1 << 1, |
| 54 FILE_NAME = 1 << 2, | 56 FILE_NAME = 1 << 2, |
| 55 PICKLED_DATA = 1 << 3, | 57 PICKLED_DATA = 1 << 3, |
| 56 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 57 FILE_CONTENTS = 1 << 4, | 59 FILE_CONTENTS = 1 << 4, |
| 58 HTML = 1 << 5, | 60 HTML = 1 << 5, |
| 59 #endif | 61 #endif |
| 60 }; | 62 }; |
| 61 | 63 |
| 64 struct DownloadFileInfo; |
| 65 |
| 66 // Defines the interface to observe the status of file download. |
| 67 class DownloadFileObserver : public base::RefCounted<DownloadFileObserver> { |
| 68 public: |
| 69 // The caller is responsible to free the DownloadFileInfo objects passed |
| 70 // in the vector parameter. |
| 71 virtual void OnDataReady( |
| 72 int format, |
| 73 const std::vector<DownloadFileInfo*>& downloads) = 0; |
| 74 |
| 75 protected: |
| 76 friend class base::RefCounted<DownloadFileObserver>; |
| 77 virtual ~DownloadFileObserver() {} |
| 78 }; |
| 79 |
| 80 // Defines the interface to control how a file is downloaded. |
| 81 class DownloadFileProvider : |
| 82 public base::RefCountedThreadSafe<DownloadFileProvider> { |
| 83 public: |
| 84 virtual bool Start(DownloadFileObserver* observer, int format) = 0; |
| 85 virtual void Stop() = 0; |
| 86 |
| 87 protected: |
| 88 friend class base::RefCountedThreadSafe<DownloadFileProvider>; |
| 89 virtual ~DownloadFileProvider() {} |
| 90 }; |
| 91 |
| 92 // Encapsulates the info about a file to be downloaded. |
| 93 struct DownloadFileInfo { |
| 94 FilePath filename; |
| 95 uint64 size; |
| 96 scoped_refptr<DownloadFileProvider> downloader; |
| 97 |
| 98 DownloadFileInfo(const FilePath& filename, |
| 99 uint64 size, |
| 100 DownloadFileProvider* downloader) |
| 101 : filename(filename), |
| 102 size(size), |
| 103 downloader(downloader) {} |
| 104 }; |
| 105 |
| 62 // Provider defines the platform specific part of OSExchangeData that | 106 // Provider defines the platform specific part of OSExchangeData that |
| 63 // interacts with the native system. | 107 // interacts with the native system. |
| 64 class Provider { | 108 class Provider { |
| 65 public: | 109 public: |
| 66 Provider() {} | 110 Provider() {} |
| 67 virtual ~Provider() {} | 111 virtual ~Provider() {} |
| 68 | 112 |
| 69 virtual void SetString(const std::wstring& data) = 0; | 113 virtual void SetString(const std::wstring& data) = 0; |
| 70 virtual void SetURL(const GURL& url, const std::wstring& title) = 0; | 114 virtual void SetURL(const GURL& url, const std::wstring& title) = 0; |
| 71 virtual void SetFilename(const std::wstring& full_path) = 0; | 115 virtual void SetFilename(const std::wstring& full_path) = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 84 | 128 |
| 85 #if defined(OS_WIN) | 129 #if defined(OS_WIN) |
| 86 virtual void SetFileContents(const std::wstring& filename, | 130 virtual void SetFileContents(const std::wstring& filename, |
| 87 const std::string& file_contents) = 0; | 131 const std::string& file_contents) = 0; |
| 88 virtual void SetHtml(const std::wstring& html, const GURL& base_url) = 0; | 132 virtual void SetHtml(const std::wstring& html, const GURL& base_url) = 0; |
| 89 virtual bool GetFileContents(std::wstring* filename, | 133 virtual bool GetFileContents(std::wstring* filename, |
| 90 std::string* file_contents) const = 0; | 134 std::string* file_contents) const = 0; |
| 91 virtual bool GetHtml(std::wstring* html, GURL* base_url) const = 0; | 135 virtual bool GetHtml(std::wstring* html, GURL* base_url) const = 0; |
| 92 virtual bool HasFileContents() const = 0; | 136 virtual bool HasFileContents() const = 0; |
| 93 virtual bool HasHtml() const = 0; | 137 virtual bool HasHtml() const = 0; |
| 138 virtual void SetDownloadFileInfo(DownloadFileInfo* download) = 0; |
| 94 #endif | 139 #endif |
| 95 }; | 140 }; |
| 96 | 141 |
| 97 OSExchangeData(); | 142 OSExchangeData(); |
| 98 // Creates an OSExchangeData with the specified provider. OSExchangeData | 143 // Creates an OSExchangeData with the specified provider. OSExchangeData |
| 99 // takes ownership of the supplied provider. | 144 // takes ownership of the supplied provider. |
| 100 explicit OSExchangeData(Provider* provider); | 145 explicit OSExchangeData(Provider* provider); |
| 101 | 146 |
| 102 ~OSExchangeData(); | 147 ~OSExchangeData(); |
| 103 | 148 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 #if defined(OS_WIN) | 202 #if defined(OS_WIN) |
| 158 // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR). | 203 // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR). |
| 159 void SetFileContents(const std::wstring& filename, | 204 void SetFileContents(const std::wstring& filename, |
| 160 const std::string& file_contents); | 205 const std::string& file_contents); |
| 161 // Adds a snippet of HTML. |html| is just raw html but this sets both | 206 // Adds a snippet of HTML. |html| is just raw html but this sets both |
| 162 // text/html and CF_HTML. | 207 // text/html and CF_HTML. |
| 163 void SetHtml(const std::wstring& html, const GURL& base_url); | 208 void SetHtml(const std::wstring& html, const GURL& base_url); |
| 164 bool GetFileContents(std::wstring* filename, | 209 bool GetFileContents(std::wstring* filename, |
| 165 std::string* file_contents) const; | 210 std::string* file_contents) const; |
| 166 bool GetHtml(std::wstring* html, GURL* base_url) const; | 211 bool GetHtml(std::wstring* html, GURL* base_url) const; |
| 212 |
| 213 // Adds a download file with full path (CF_HDROP). |
| 214 void SetDownloadFileInfo(DownloadFileInfo* download); |
| 167 #endif | 215 #endif |
| 168 | 216 |
| 169 private: | 217 private: |
| 170 // Creates the platform specific Provider. | 218 // Creates the platform specific Provider. |
| 171 static Provider* CreateProvider(); | 219 static Provider* CreateProvider(); |
| 172 | 220 |
| 173 // Provides the actual data. | 221 // Provides the actual data. |
| 174 scoped_ptr<Provider> provider_; | 222 scoped_ptr<Provider> provider_; |
| 175 | 223 |
| 176 DISALLOW_COPY_AND_ASSIGN(OSExchangeData); | 224 DISALLOW_COPY_AND_ASSIGN(OSExchangeData); |
| 177 }; | 225 }; |
| 178 | 226 |
| 179 #endif // APP_OS_EXCHANGE_DATA_H_ | 227 #endif // APP_OS_EXCHANGE_DATA_H_ |
| OLD | NEW |