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 10namespace ui { 11 12OSExchangeData::DownloadFileInfo::DownloadFileInfo( 13 const base::FilePath& filename, 14 DownloadFileProvider* downloader) 15 : filename(filename), 16 downloader(downloader) { 17} 18 19OSExchangeData::DownloadFileInfo::~DownloadFileInfo() {} 20 21OSExchangeData::OSExchangeData() : provider_(CreateProvider()) { 22} 23 24OSExchangeData::OSExchangeData(Provider* provider) : provider_(provider) { 25} 26 27OSExchangeData::~OSExchangeData() { 28} 29 30void OSExchangeData::MarkOriginatedFromRenderer() { 31 provider_->MarkOriginatedFromRenderer(); 32} 33 34bool OSExchangeData::DidOriginateFromRenderer() const { 35 return provider_->DidOriginateFromRenderer(); 36} 37 38void OSExchangeData::SetString(const base::string16& data) { 39 provider_->SetString(data); 40} 41 42void OSExchangeData::SetURL(const GURL& url, const base::string16& title) { 43 provider_->SetURL(url, title); 44} 45 46void OSExchangeData::SetFilename(const base::FilePath& path) { 47 provider_->SetFilename(path); 48} 49 50void OSExchangeData::SetFilenames( 51 const std::vector<FileInfo>& filenames) { 52 provider_->SetFilenames(filenames); 53} 54 55void OSExchangeData::SetPickledData(const CustomFormat& format, 56 const Pickle& data) { 57 provider_->SetPickledData(format, data); 58} 59 60bool OSExchangeData::GetString(base::string16* data) const { 61 return provider_->GetString(data); 62} 63 64bool OSExchangeData::GetURLAndTitle(FilenameToURLPolicy policy, 65 GURL* url, 66 base::string16* title) const { 67 return provider_->GetURLAndTitle(policy, url, title); 68} 69 70bool OSExchangeData::GetFilename(base::FilePath* path) const { 71 return provider_->GetFilename(path); 72} 73 74bool OSExchangeData::GetFilenames( 75 std::vector<FileInfo>* filenames) const { 76 return provider_->GetFilenames(filenames); 77} 78 79bool OSExchangeData::GetPickledData(const CustomFormat& format, 80 Pickle* data) const { 81 return provider_->GetPickledData(format, data); 82} 83 84bool OSExchangeData::HasString() const { 85 return provider_->HasString(); 86} 87 88bool OSExchangeData::HasURL(FilenameToURLPolicy policy) const { 89 return provider_->HasURL(policy); 90} 91 92bool OSExchangeData::HasFile() const { 93 return provider_->HasFile(); 94} 95 96bool OSExchangeData::HasCustomFormat(const CustomFormat& format) const { 97 return provider_->HasCustomFormat(format); 98} 99 100bool 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) 126void OSExchangeData::SetFileContents(const base::FilePath& filename, 127 const std::string& file_contents) { 128 provider_->SetFileContents(filename, file_contents); 129} 130 131bool OSExchangeData::GetFileContents(base::FilePath* filename, 132 std::string* file_contents) const { 133 return provider_->GetFileContents(filename, file_contents); 134} 135 136void OSExchangeData::SetDownloadFileInfo(const DownloadFileInfo& download) { 137 provider_->SetDownloadFileInfo(download); 138} 139#endif 140 141#if defined(USE_AURA) 142void OSExchangeData::SetHtml(const base::string16& html, const GURL& base_url) { 143 provider_->SetHtml(html, base_url); 144} 145 146bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const { 147 return provider_->GetHtml(html, base_url); 148} 149#endif 150 151} // namespace ui 152