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
DownloadFileInfo(const base::FilePath & filename,DownloadFileProvider * downloader)12 OSExchangeData::DownloadFileInfo::DownloadFileInfo(
13 const base::FilePath& filename,
14 DownloadFileProvider* downloader)
15 : filename(filename),
16 downloader(downloader) {
17 }
18
~DownloadFileInfo()19 OSExchangeData::DownloadFileInfo::~DownloadFileInfo() {}
20
OSExchangeData()21 OSExchangeData::OSExchangeData() : provider_(CreateProvider()) {
22 }
23
OSExchangeData(Provider * provider)24 OSExchangeData::OSExchangeData(Provider* provider) : provider_(provider) {
25 }
26
~OSExchangeData()27 OSExchangeData::~OSExchangeData() {
28 }
29
MarkOriginatedFromRenderer()30 void OSExchangeData::MarkOriginatedFromRenderer() {
31 provider_->MarkOriginatedFromRenderer();
32 }
33
DidOriginateFromRenderer() const34 bool OSExchangeData::DidOriginateFromRenderer() const {
35 return provider_->DidOriginateFromRenderer();
36 }
37
SetString(const base::string16 & data)38 void OSExchangeData::SetString(const base::string16& data) {
39 provider_->SetString(data);
40 }
41
SetURL(const GURL & url,const base::string16 & title)42 void OSExchangeData::SetURL(const GURL& url, const base::string16& title) {
43 provider_->SetURL(url, title);
44 }
45
SetFilename(const base::FilePath & path)46 void OSExchangeData::SetFilename(const base::FilePath& path) {
47 provider_->SetFilename(path);
48 }
49
SetFilenames(const std::vector<FileInfo> & filenames)50 void OSExchangeData::SetFilenames(
51 const std::vector<FileInfo>& filenames) {
52 provider_->SetFilenames(filenames);
53 }
54
SetPickledData(const CustomFormat & format,const Pickle & data)55 void OSExchangeData::SetPickledData(const CustomFormat& format,
56 const Pickle& data) {
57 provider_->SetPickledData(format, data);
58 }
59
GetString(base::string16 * data) const60 bool OSExchangeData::GetString(base::string16* data) const {
61 return provider_->GetString(data);
62 }
63
GetURLAndTitle(FilenameToURLPolicy policy,GURL * url,base::string16 * title) const64 bool OSExchangeData::GetURLAndTitle(FilenameToURLPolicy policy,
65 GURL* url,
66 base::string16* title) const {
67 return provider_->GetURLAndTitle(policy, url, title);
68 }
69
GetFilename(base::FilePath * path) const70 bool OSExchangeData::GetFilename(base::FilePath* path) const {
71 return provider_->GetFilename(path);
72 }
73
GetFilenames(std::vector<FileInfo> * filenames) const74 bool OSExchangeData::GetFilenames(
75 std::vector<FileInfo>* filenames) const {
76 return provider_->GetFilenames(filenames);
77 }
78
GetPickledData(const CustomFormat & format,Pickle * data) const79 bool OSExchangeData::GetPickledData(const CustomFormat& format,
80 Pickle* data) const {
81 return provider_->GetPickledData(format, data);
82 }
83
HasString() const84 bool OSExchangeData::HasString() const {
85 return provider_->HasString();
86 }
87
HasURL(FilenameToURLPolicy policy) const88 bool OSExchangeData::HasURL(FilenameToURLPolicy policy) const {
89 return provider_->HasURL(policy);
90 }
91
HasFile() const92 bool OSExchangeData::HasFile() const {
93 return provider_->HasFile();
94 }
95
HasCustomFormat(const CustomFormat & format) const96 bool OSExchangeData::HasCustomFormat(const CustomFormat& format) const {
97 return provider_->HasCustomFormat(format);
98 }
99
HasAnyFormat(int formats,const std::set<CustomFormat> & custom_formats) const100 bool OSExchangeData::HasAnyFormat(
101 int formats,
102 const std::set<CustomFormat>& custom_formats) const {
103 if ((formats & STRING) != 0 && HasString())
104 return true;
105 if ((formats & URL) != 0 && HasURL(CONVERT_FILENAMES))
106 return true;
107 #if defined(OS_WIN)
108 if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents())
109 return true;
110 #endif
111 #if defined(USE_AURA)
112 if ((formats & HTML) != 0 && provider_->HasHtml())
113 return true;
114 #endif
115 if ((formats & FILE_NAME) != 0 && provider_->HasFile())
116 return true;
117 for (std::set<CustomFormat>::const_iterator i = custom_formats.begin();
118 i != custom_formats.end(); ++i) {
119 if (HasCustomFormat(*i))
120 return true;
121 }
122 return false;
123 }
124
125 #if defined(OS_WIN)
SetFileContents(const base::FilePath & filename,const std::string & file_contents)126 void OSExchangeData::SetFileContents(const base::FilePath& filename,
127 const std::string& file_contents) {
128 provider_->SetFileContents(filename, file_contents);
129 }
130
GetFileContents(base::FilePath * filename,std::string * file_contents) const131 bool OSExchangeData::GetFileContents(base::FilePath* filename,
132 std::string* file_contents) const {
133 return provider_->GetFileContents(filename, file_contents);
134 }
135
SetDownloadFileInfo(const DownloadFileInfo & download)136 void OSExchangeData::SetDownloadFileInfo(const DownloadFileInfo& download) {
137 provider_->SetDownloadFileInfo(download);
138 }
139 #endif
140
141 #if defined(USE_AURA)
SetHtml(const base::string16 & html,const GURL & base_url)142 void OSExchangeData::SetHtml(const base::string16& html, const GURL& base_url) {
143 provider_->SetHtml(html, base_url);
144 }
145
GetHtml(base::string16 * html,GURL * base_url) const146 bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const {
147 return provider_->GetHtml(html, base_url);
148 }
149 #endif
150
151 } // namespace ui
152