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(FilenameToURLPolicy policy, 66 GURL* url, 67 base::string16* title) const { 68 return provider_->GetURLAndTitle(policy, url, title); 69 } 70 71 bool OSExchangeData::GetFilename(base::FilePath* path) const { 72 return provider_->GetFilename(path); 73 } 74 75 bool OSExchangeData::GetFilenames( 76 std::vector<FileInfo>* filenames) const { 77 return provider_->GetFilenames(filenames); 78 } 79 80 bool OSExchangeData::GetPickledData(const CustomFormat& format, 81 Pickle* data) const { 82 return provider_->GetPickledData(format, data); 83 } 84 85 bool OSExchangeData::HasString() const { 86 return provider_->HasString(); 87 } 88 89 bool OSExchangeData::HasURL() const { 90 return provider_->HasURL(); 91 } 92 93 bool OSExchangeData::HasFile() const { 94 return provider_->HasFile(); 95 } 96 97 bool OSExchangeData::HasCustomFormat(const CustomFormat& format) const { 98 return provider_->HasCustomFormat(format); 99 } 100 101 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 126 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) 152 void OSExchangeData::SetFileContents(const base::FilePath& filename, 153 const std::string& file_contents) { 154 provider_->SetFileContents(filename, file_contents); 155 } 156 157 bool OSExchangeData::GetFileContents(base::FilePath* filename, 158 std::string* file_contents) const { 159 return provider_->GetFileContents(filename, file_contents); 160 } 161 162 void OSExchangeData::SetDownloadFileInfo(const DownloadFileInfo& download) { 163 provider_->SetDownloadFileInfo(download); 164 } 165 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) 172 void OSExchangeData::SetHtml(const base::string16& html, const GURL& base_url) { 173 provider_->SetHtml(html, base_url); 174 } 175 176 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