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.
5 #include "ui/base/dragdrop/os_exchange_data.h"
7 #include "base/pickle.h"
12 OSExchangeData::DownloadFileInfo::DownloadFileInfo(
13 const base::FilePath& filename,
14 DownloadFileProvider* downloader)
16 downloader(downloader) {
19 OSExchangeData::DownloadFileInfo::~DownloadFileInfo() {}
21 OSExchangeData::FileInfo::FileInfo(
22 const base::FilePath& path,
23 const base::FilePath& display_name)
25 display_name(display_name) {
28 OSExchangeData::FileInfo::~FileInfo() {}
30 OSExchangeData::OSExchangeData() : provider_(CreateProvider()) {
33 OSExchangeData::OSExchangeData(Provider* provider) : provider_(provider) {
36 OSExchangeData::~OSExchangeData() {
39 void OSExchangeData::SetString(const base::string16& data) {
40 provider_->SetString(data);
43 void OSExchangeData::SetURL(const GURL& url, const base::string16& title) {
44 provider_->SetURL(url, title);
47 void OSExchangeData::SetFilename(const base::FilePath& path) {
48 provider_->SetFilename(path);
51 void OSExchangeData::SetFilenames(
52 const std::vector<FileInfo>& filenames) {
53 provider_->SetFilenames(filenames);
56 void OSExchangeData::SetPickledData(const CustomFormat& format,
58 provider_->SetPickledData(format, data);
61 bool OSExchangeData::GetString(base::string16* data) const {
62 return provider_->GetString(data);
65 bool OSExchangeData::GetURLAndTitle(GURL* url, base::string16* title) const {
66 return provider_->GetURLAndTitle(url, title);
69 bool OSExchangeData::GetFilename(base::FilePath* path) const {
70 return provider_->GetFilename(path);
73 bool OSExchangeData::GetFilenames(
74 std::vector<FileInfo>* filenames) const {
75 return provider_->GetFilenames(filenames);
78 bool OSExchangeData::GetPickledData(const CustomFormat& format,
80 return provider_->GetPickledData(format, data);
83 bool OSExchangeData::HasString() const {
84 return provider_->HasString();
87 bool OSExchangeData::HasURL() const {
88 return provider_->HasURL();
91 bool OSExchangeData::HasFile() const {
92 return provider_->HasFile();
95 bool OSExchangeData::HasCustomFormat(const CustomFormat& format) const {
96 return provider_->HasCustomFormat(format);
99 bool OSExchangeData::HasAllFormats(
101 const std::set<CustomFormat>& custom_formats) const {
102 if ((formats & STRING) != 0 && !HasString())
104 if ((formats & URL) != 0 && !HasURL())
107 if ((formats & FILE_CONTENTS) != 0 && !provider_->HasFileContents())
110 #if defined(OS_WIN) || defined(USE_AURA)
111 if ((formats & HTML) != 0 && !provider_->HasHtml())
114 if ((formats & FILE_NAME) != 0 && !provider_->HasFile())
116 for (std::set<CustomFormat>::const_iterator i = custom_formats.begin();
117 i != custom_formats.end(); ++i) {
118 if (!HasCustomFormat(*i))
124 bool OSExchangeData::HasAnyFormat(
126 const std::set<CustomFormat>& custom_formats) const {
127 if ((formats & STRING) != 0 && HasString())
129 if ((formats & URL) != 0 && HasURL())
132 if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents())
135 #if defined(OS_WIN) || defined(USE_AURA)
136 if ((formats & HTML) != 0 && provider_->HasHtml())
139 if ((formats & FILE_NAME) != 0 && provider_->HasFile())
141 for (std::set<CustomFormat>::const_iterator i = custom_formats.begin();
142 i != custom_formats.end(); ++i) {
143 if (HasCustomFormat(*i))
150 void OSExchangeData::SetFileContents(const base::FilePath& filename,
151 const std::string& file_contents) {
152 provider_->SetFileContents(filename, file_contents);
155 bool OSExchangeData::GetFileContents(base::FilePath* filename,
156 std::string* file_contents) const {
157 return provider_->GetFileContents(filename, file_contents);
160 void OSExchangeData::SetDownloadFileInfo(const DownloadFileInfo& download) {
161 provider_->SetDownloadFileInfo(download);
164 void OSExchangeData::SetInDragLoop(bool in_drag_loop) {
165 provider_->SetInDragLoop(in_drag_loop);
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);
174 bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const {
175 return provider_->GetHtml(html, base_url);