- add sources.
[platform/framework/web/crosswalk.git] / src / ui / base / dragdrop / os_exchange_data.cc
1 // Copyright (c) 2012 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 #include "ui/base/dragdrop/os_exchange_data.h"
6
7 #include "base/pickle.h"
8 #include "url/gurl.h"
9
10 namespace ui {
11
12 OSExchangeData::DownloadFileInfo::DownloadFileInfo(
13     const base::FilePath& filename,
14     DownloadFileProvider* downloader)
15     : filename(filename),
16       downloader(downloader) {
17 }
18
19 OSExchangeData::DownloadFileInfo::~DownloadFileInfo() {}
20
21 OSExchangeData::FileInfo::FileInfo(
22     const base::FilePath& path,
23     const base::FilePath& display_name)
24     : path(path),
25       display_name(display_name) {
26 }
27
28 OSExchangeData::FileInfo::~FileInfo() {}
29
30 OSExchangeData::OSExchangeData() : provider_(CreateProvider()) {
31 }
32
33 OSExchangeData::OSExchangeData(Provider* provider) : provider_(provider) {
34 }
35
36 OSExchangeData::~OSExchangeData() {
37 }
38
39 void OSExchangeData::SetString(const base::string16& data) {
40   provider_->SetString(data);
41 }
42
43 void OSExchangeData::SetURL(const GURL& url, const base::string16& title) {
44   provider_->SetURL(url, title);
45 }
46
47 void OSExchangeData::SetFilename(const base::FilePath& path) {
48   provider_->SetFilename(path);
49 }
50
51 void OSExchangeData::SetFilenames(
52     const std::vector<FileInfo>& filenames) {
53   provider_->SetFilenames(filenames);
54 }
55
56 void OSExchangeData::SetPickledData(const CustomFormat& format,
57                                     const Pickle& data) {
58   provider_->SetPickledData(format, data);
59 }
60
61 bool OSExchangeData::GetString(base::string16* data) const {
62   return provider_->GetString(data);
63 }
64
65 bool OSExchangeData::GetURLAndTitle(GURL* url, base::string16* title) const {
66   return provider_->GetURLAndTitle(url, title);
67 }
68
69 bool OSExchangeData::GetFilename(base::FilePath* path) const {
70   return provider_->GetFilename(path);
71 }
72
73 bool OSExchangeData::GetFilenames(
74     std::vector<FileInfo>* filenames) const {
75   return provider_->GetFilenames(filenames);
76 }
77
78 bool OSExchangeData::GetPickledData(const CustomFormat& format,
79                                     Pickle* data) const {
80   return provider_->GetPickledData(format, data);
81 }
82
83 bool OSExchangeData::HasString() const {
84   return provider_->HasString();
85 }
86
87 bool OSExchangeData::HasURL() const {
88   return provider_->HasURL();
89 }
90
91 bool OSExchangeData::HasFile() const {
92   return provider_->HasFile();
93 }
94
95 bool OSExchangeData::HasCustomFormat(const CustomFormat& format) const {
96   return provider_->HasCustomFormat(format);
97 }
98
99 bool OSExchangeData::HasAllFormats(
100     int formats,
101     const std::set<CustomFormat>& custom_formats) const {
102   if ((formats & STRING) != 0 && !HasString())
103     return false;
104   if ((formats & URL) != 0 && !HasURL())
105     return false;
106 #if defined(OS_WIN)
107   if ((formats & FILE_CONTENTS) != 0 && !provider_->HasFileContents())
108     return false;
109 #endif
110 #if defined(OS_WIN) || defined(USE_AURA)
111   if ((formats & HTML) != 0 && !provider_->HasHtml())
112     return false;
113 #endif
114   if ((formats & FILE_NAME) != 0 && !provider_->HasFile())
115     return false;
116   for (std::set<CustomFormat>::const_iterator i = custom_formats.begin();
117        i != custom_formats.end(); ++i) {
118     if (!HasCustomFormat(*i))
119       return false;
120   }
121   return true;
122 }
123
124 bool OSExchangeData::HasAnyFormat(
125     int formats,
126     const std::set<CustomFormat>& custom_formats) const {
127   if ((formats & STRING) != 0 && HasString())
128     return true;
129   if ((formats & URL) != 0 && HasURL())
130     return true;
131 #if defined(OS_WIN)
132   if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents())
133     return true;
134 #endif
135 #if defined(OS_WIN) || defined(USE_AURA)
136   if ((formats & HTML) != 0 && provider_->HasHtml())
137     return true;
138 #endif
139   if ((formats & FILE_NAME) != 0 && provider_->HasFile())
140     return true;
141   for (std::set<CustomFormat>::const_iterator i = custom_formats.begin();
142        i != custom_formats.end(); ++i) {
143     if (HasCustomFormat(*i))
144       return true;
145   }
146   return false;
147 }
148
149 #if defined(OS_WIN)
150 void OSExchangeData::SetFileContents(const base::FilePath& filename,
151                                      const std::string& file_contents) {
152   provider_->SetFileContents(filename, file_contents);
153 }
154
155 bool OSExchangeData::GetFileContents(base::FilePath* filename,
156                                      std::string* file_contents) const {
157   return provider_->GetFileContents(filename, file_contents);
158 }
159
160 void OSExchangeData::SetDownloadFileInfo(const DownloadFileInfo& download) {
161   provider_->SetDownloadFileInfo(download);
162 }
163
164 void OSExchangeData::SetInDragLoop(bool in_drag_loop) {
165   provider_->SetInDragLoop(in_drag_loop);
166 }
167 #endif
168
169 #if defined(OS_WIN) || defined(USE_AURA)
170 void OSExchangeData::SetHtml(const base::string16& html, const GURL& base_url) {
171   provider_->SetHtml(html, base_url);
172 }
173
174 bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const {
175   return provider_->GetHtml(html, base_url);
176 }
177 #endif
178
179 }  // namespace ui