Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: app/os_exchange_data.h

Issue 6200005: Move OSExchangeData from src/app to src/ui/base/dragdrop... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/app_base.gypi ('k') | app/os_exchange_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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_H_
6 #define APP_OS_EXCHANGE_DATA_H_
7 #pragma once
8
9 #include "build/build_config.h"
10
11 #include <set>
12 #include <string>
13
14 #if defined(OS_WIN)
15 #include <objidl.h>
16 #elif !defined(OS_MACOSX)
17 #include <gtk/gtk.h>
18 #endif
19
20 #include "app/download_file_interface.h"
21 #include "base/basictypes.h"
22 #include "base/file_path.h"
23 #include "base/scoped_ptr.h"
24
25 class GURL;
26 class Pickle;
27
28 ///////////////////////////////////////////////////////////////////////////////
29 //
30 // OSExchangeData
31 // An object that holds interchange data to be sent out to OS services like
32 // clipboard, drag and drop, etc. This object exposes an API that clients can
33 // use to specify raw data and its high level type. This object takes care of
34 // translating that into something the OS can understand.
35 //
36 ///////////////////////////////////////////////////////////////////////////////
37
38 // NOTE: Support for html and file contents is required by TabContentViewWin.
39 // TabContentsViewGtk uses a different class to handle drag support that does
40 // not use OSExchangeData. As such, file contents and html support is only
41 // compiled on windows.
42 class OSExchangeData {
43 public:
44 // CustomFormats are used for non-standard data types. For example, bookmark
45 // nodes are written using a CustomFormat.
46 #if defined(OS_WIN)
47 typedef CLIPFORMAT CustomFormat;
48 #elif !defined(OS_MACOSX)
49 typedef GdkAtom CustomFormat;
50 #endif
51
52 // Enumeration of the known formats.
53 enum Format {
54 STRING = 1 << 0,
55 URL = 1 << 1,
56 FILE_NAME = 1 << 2,
57 PICKLED_DATA = 1 << 3,
58 #if defined(OS_WIN)
59 FILE_CONTENTS = 1 << 4,
60 HTML = 1 << 5,
61 #endif
62 };
63
64 // Encapsulates the info about a file to be downloaded.
65 struct DownloadFileInfo {
66 DownloadFileInfo(const FilePath& filename,
67 DownloadFileProvider* downloader);
68 ~DownloadFileInfo();
69
70 FilePath filename;
71 scoped_refptr<DownloadFileProvider> downloader;
72 };
73
74 // Provider defines the platform specific part of OSExchangeData that
75 // interacts with the native system.
76 class Provider {
77 public:
78 Provider() {}
79 virtual ~Provider() {}
80
81 virtual void SetString(const std::wstring& data) = 0;
82 virtual void SetURL(const GURL& url, const std::wstring& title) = 0;
83 virtual void SetFilename(const std::wstring& full_path) = 0;
84 virtual void SetPickledData(CustomFormat format, const Pickle& data) = 0;
85
86 virtual bool GetString(std::wstring* data) const = 0;
87 virtual bool GetURLAndTitle(GURL* url, std::wstring* title) const = 0;
88 virtual bool GetFilename(std::wstring* full_path) const = 0;
89 virtual bool GetPickledData(CustomFormat format, Pickle* data) const = 0;
90
91 virtual bool HasString() const = 0;
92 virtual bool HasURL() const = 0;
93 virtual bool HasFile() const = 0;
94 virtual bool HasCustomFormat(
95 OSExchangeData::CustomFormat format) const = 0;
96
97 #if defined(OS_WIN)
98 virtual void SetFileContents(const std::wstring& filename,
99 const std::string& file_contents) = 0;
100 virtual void SetHtml(const std::wstring& html, const GURL& base_url) = 0;
101 virtual bool GetFileContents(std::wstring* filename,
102 std::string* file_contents) const = 0;
103 virtual bool GetHtml(std::wstring* html, GURL* base_url) const = 0;
104 virtual bool HasFileContents() const = 0;
105 virtual bool HasHtml() const = 0;
106 virtual void SetDownloadFileInfo(const DownloadFileInfo& download) = 0;
107 #endif
108 };
109
110 OSExchangeData();
111 // Creates an OSExchangeData with the specified provider. OSExchangeData
112 // takes ownership of the supplied provider.
113 explicit OSExchangeData(Provider* provider);
114
115 ~OSExchangeData();
116
117 // Registers the specific string as a possible format for data.
118 static CustomFormat RegisterCustomFormat(const std::string& type);
119
120 // Returns the Provider, which actually stores and manages the data.
121 const Provider& provider() const { return *provider_; }
122 Provider& provider() { return *provider_; }
123
124 // These functions add data to the OSExchangeData object of various Chrome
125 // types. The OSExchangeData object takes care of translating the data into
126 // a format suitable for exchange with the OS.
127 // NOTE WELL: Typically, a data object like this will contain only one of the
128 // following types of data. In cases where more data is held, the
129 // order in which these functions are called is _important_!
130 // ---> The order types are added to an OSExchangeData object controls
131 // the order of enumeration in our IEnumFORMATETC implementation!
132 // This comes into play when selecting the best (most preferable)
133 // data type for insertion into a DropTarget.
134 void SetString(const std::wstring& data);
135 // A URL can have an optional title in some exchange formats.
136 void SetURL(const GURL& url, const std::wstring& title);
137 // A full path to a file.
138 // TODO: convert to Filepath.
139 void SetFilename(const std::wstring& full_path);
140 // Adds pickled data of the specified format.
141 void SetPickledData(CustomFormat format, const Pickle& data);
142
143 // These functions retrieve data of the specified type. If data exists, the
144 // functions return and the result is in the out parameter. If the data does
145 // not exist, the out parameter is not touched. The out parameter cannot be
146 // NULL.
147 bool GetString(std::wstring* data) const;
148 bool GetURLAndTitle(GURL* url, std::wstring* title) const;
149 // Return the path of a file, if available.
150 bool GetFilename(std::wstring* full_path) const;
151 bool GetPickledData(CustomFormat format, Pickle* data) const;
152
153 // Test whether or not data of certain types is present, without actually
154 // returning anything.
155 bool HasString() const;
156 bool HasURL() const;
157 bool HasFile() const;
158 bool HasCustomFormat(CustomFormat format) const;
159
160 // Returns true if this OSExchangeData has data for ALL the formats in
161 // |formats| and ALL the custom formats in |custom_formats|.
162 bool HasAllFormats(int formats,
163 const std::set<CustomFormat>& custom_formats) const;
164
165 // Returns true if this OSExchangeData has data in any of the formats in
166 // |formats| or any custom format in |custom_formats|.
167 bool HasAnyFormat(int formats,
168 const std::set<CustomFormat>& custom_formats) const;
169
170 #if defined(OS_WIN)
171 // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR).
172 void SetFileContents(const std::wstring& filename,
173 const std::string& file_contents);
174 // Adds a snippet of HTML. |html| is just raw html but this sets both
175 // text/html and CF_HTML.
176 void SetHtml(const std::wstring& html, const GURL& base_url);
177 bool GetFileContents(std::wstring* filename,
178 std::string* file_contents) const;
179 bool GetHtml(std::wstring* html, GURL* base_url) const;
180
181 // Adds a download file with full path (CF_HDROP).
182 void SetDownloadFileInfo(const DownloadFileInfo& download);
183 #endif
184
185 private:
186 // Creates the platform specific Provider.
187 static Provider* CreateProvider();
188
189 // Provides the actual data.
190 scoped_ptr<Provider> provider_;
191
192 DISALLOW_COPY_AND_ASSIGN(OSExchangeData);
193 };
194
195 #endif // APP_OS_EXCHANGE_DATA_H_
OLDNEW
« no previous file with comments | « app/app_base.gypi ('k') | app/os_exchange_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698