• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
FileInfo(const base::FilePath & path,const base::FilePath & display_name)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 
~FileInfo()28 OSExchangeData::FileInfo::~FileInfo() {}
29 
OSExchangeData()30 OSExchangeData::OSExchangeData() : provider_(CreateProvider()) {
31 }
32 
OSExchangeData(Provider * provider)33 OSExchangeData::OSExchangeData(Provider* provider) : provider_(provider) {
34 }
35 
~OSExchangeData()36 OSExchangeData::~OSExchangeData() {
37 }
38 
SetString(const base::string16 & data)39 void OSExchangeData::SetString(const base::string16& data) {
40   provider_->SetString(data);
41 }
42 
SetURL(const GURL & url,const base::string16 & title)43 void OSExchangeData::SetURL(const GURL& url, const base::string16& title) {
44   provider_->SetURL(url, title);
45 }
46 
SetFilename(const base::FilePath & path)47 void OSExchangeData::SetFilename(const base::FilePath& path) {
48   provider_->SetFilename(path);
49 }
50 
SetFilenames(const std::vector<FileInfo> & filenames)51 void OSExchangeData::SetFilenames(
52     const std::vector<FileInfo>& filenames) {
53   provider_->SetFilenames(filenames);
54 }
55 
SetPickledData(const CustomFormat & format,const Pickle & data)56 void OSExchangeData::SetPickledData(const CustomFormat& format,
57                                     const Pickle& data) {
58   provider_->SetPickledData(format, data);
59 }
60 
GetString(base::string16 * data) const61 bool OSExchangeData::GetString(base::string16* data) const {
62   return provider_->GetString(data);
63 }
64 
GetURLAndTitle(FilenameToURLPolicy policy,GURL * url,base::string16 * title) const65 bool OSExchangeData::GetURLAndTitle(FilenameToURLPolicy policy,
66                                     GURL* url,
67                                     base::string16* title) const {
68   return provider_->GetURLAndTitle(policy, url, title);
69 }
70 
GetFilename(base::FilePath * path) const71 bool OSExchangeData::GetFilename(base::FilePath* path) const {
72   return provider_->GetFilename(path);
73 }
74 
GetFilenames(std::vector<FileInfo> * filenames) const75 bool OSExchangeData::GetFilenames(
76     std::vector<FileInfo>* filenames) const {
77   return provider_->GetFilenames(filenames);
78 }
79 
GetPickledData(const CustomFormat & format,Pickle * data) const80 bool OSExchangeData::GetPickledData(const CustomFormat& format,
81                                     Pickle* data) const {
82   return provider_->GetPickledData(format, data);
83 }
84 
HasString() const85 bool OSExchangeData::HasString() const {
86   return provider_->HasString();
87 }
88 
HasURL() const89 bool OSExchangeData::HasURL() const {
90   return provider_->HasURL();
91 }
92 
HasFile() const93 bool OSExchangeData::HasFile() const {
94   return provider_->HasFile();
95 }
96 
HasCustomFormat(const CustomFormat & format) const97 bool OSExchangeData::HasCustomFormat(const CustomFormat& format) const {
98   return provider_->HasCustomFormat(format);
99 }
100 
HasAllFormats(int formats,const std::set<CustomFormat> & custom_formats) const101 bool OSExchangeData::HasAllFormats(
102     int formats,
103     const std::set<CustomFormat>& custom_formats) const {
104   if ((formats & STRING) != 0 && !HasString())
105     return false;
106   if ((formats & URL) != 0 && !HasURL())
107     return false;
108 #if defined(OS_WIN)
109   if ((formats & FILE_CONTENTS) != 0 && !provider_->HasFileContents())
110     return false;
111 #endif
112 #if defined(OS_WIN) || defined(USE_AURA)
113   if ((formats & HTML) != 0 && !provider_->HasHtml())
114     return false;
115 #endif
116   if ((formats & FILE_NAME) != 0 && !provider_->HasFile())
117     return false;
118   for (std::set<CustomFormat>::const_iterator i = custom_formats.begin();
119        i != custom_formats.end(); ++i) {
120     if (!HasCustomFormat(*i))
121       return false;
122   }
123   return true;
124 }
125 
HasAnyFormat(int formats,const std::set<CustomFormat> & custom_formats) const126 bool OSExchangeData::HasAnyFormat(
127     int formats,
128     const std::set<CustomFormat>& custom_formats) const {
129   if ((formats & STRING) != 0 && HasString())
130     return true;
131   if ((formats & URL) != 0 && HasURL())
132     return true;
133 #if defined(OS_WIN)
134   if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents())
135     return true;
136 #endif
137 #if defined(OS_WIN) || defined(USE_AURA)
138   if ((formats & HTML) != 0 && provider_->HasHtml())
139     return true;
140 #endif
141   if ((formats & FILE_NAME) != 0 && provider_->HasFile())
142     return true;
143   for (std::set<CustomFormat>::const_iterator i = custom_formats.begin();
144        i != custom_formats.end(); ++i) {
145     if (HasCustomFormat(*i))
146       return true;
147   }
148   return false;
149 }
150 
151 #if defined(OS_WIN)
SetFileContents(const base::FilePath & filename,const std::string & file_contents)152 void OSExchangeData::SetFileContents(const base::FilePath& filename,
153                                      const std::string& file_contents) {
154   provider_->SetFileContents(filename, file_contents);
155 }
156 
GetFileContents(base::FilePath * filename,std::string * file_contents) const157 bool OSExchangeData::GetFileContents(base::FilePath* filename,
158                                      std::string* file_contents) const {
159   return provider_->GetFileContents(filename, file_contents);
160 }
161 
SetDownloadFileInfo(const DownloadFileInfo & download)162 void OSExchangeData::SetDownloadFileInfo(const DownloadFileInfo& download) {
163   provider_->SetDownloadFileInfo(download);
164 }
165 
SetInDragLoop(bool in_drag_loop)166 void OSExchangeData::SetInDragLoop(bool in_drag_loop) {
167   provider_->SetInDragLoop(in_drag_loop);
168 }
169 #endif
170 
171 #if defined(OS_WIN) || defined(USE_AURA)
SetHtml(const base::string16 & html,const GURL & base_url)172 void OSExchangeData::SetHtml(const base::string16& html, const GURL& base_url) {
173   provider_->SetHtml(html, base_url);
174 }
175 
GetHtml(base::string16 * html,GURL * base_url) const176 bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const {
177   return provider_->GetHtml(html, base_url);
178 }
179 #endif
180 
181 }  // namespace ui
182