Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / base / dragdrop / os_exchange_data.cc
blobc236a46730549b08c9e62793b5754df0b970a4bd
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"
8 #include "url/gurl.h"
10 namespace ui {
12 OSExchangeData::DownloadFileInfo::DownloadFileInfo(
13 const base::FilePath& filename,
14 DownloadFileProvider* downloader)
15 : filename(filename),
16 downloader(downloader) {
19 OSExchangeData::DownloadFileInfo::~DownloadFileInfo() {}
21 OSExchangeData::OSExchangeData() : provider_(CreateProvider()) {
24 OSExchangeData::OSExchangeData(Provider* provider) : provider_(provider) {
27 OSExchangeData::~OSExchangeData() {
30 void OSExchangeData::MarkOriginatedFromRenderer() {
31 provider_->MarkOriginatedFromRenderer();
34 bool OSExchangeData::DidOriginateFromRenderer() const {
35 return provider_->DidOriginateFromRenderer();
38 void OSExchangeData::SetString(const base::string16& data) {
39 provider_->SetString(data);
42 void OSExchangeData::SetURL(const GURL& url, const base::string16& title) {
43 provider_->SetURL(url, title);
46 void OSExchangeData::SetFilename(const base::FilePath& path) {
47 provider_->SetFilename(path);
50 void OSExchangeData::SetFilenames(
51 const std::vector<FileInfo>& filenames) {
52 provider_->SetFilenames(filenames);
55 void OSExchangeData::SetPickledData(const CustomFormat& format,
56 const Pickle& data) {
57 provider_->SetPickledData(format, data);
60 bool OSExchangeData::GetString(base::string16* data) const {
61 return provider_->GetString(data);
64 bool OSExchangeData::GetURLAndTitle(FilenameToURLPolicy policy,
65 GURL* url,
66 base::string16* title) const {
67 return provider_->GetURLAndTitle(policy, url, title);
70 bool OSExchangeData::GetFilename(base::FilePath* path) const {
71 return provider_->GetFilename(path);
74 bool OSExchangeData::GetFilenames(
75 std::vector<FileInfo>* filenames) const {
76 return provider_->GetFilenames(filenames);
79 bool OSExchangeData::GetPickledData(const CustomFormat& format,
80 Pickle* data) const {
81 return provider_->GetPickledData(format, data);
84 bool OSExchangeData::HasString() const {
85 return provider_->HasString();
88 bool OSExchangeData::HasURL(FilenameToURLPolicy policy) const {
89 return provider_->HasURL(policy);
92 bool OSExchangeData::HasFile() const {
93 return provider_->HasFile();
96 bool OSExchangeData::HasCustomFormat(const CustomFormat& format) const {
97 return provider_->HasCustomFormat(format);
100 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;
122 return false;
125 #if defined(OS_WIN)
126 void OSExchangeData::SetFileContents(const base::FilePath& filename,
127 const std::string& file_contents) {
128 provider_->SetFileContents(filename, file_contents);
131 bool OSExchangeData::GetFileContents(base::FilePath* filename,
132 std::string* file_contents) const {
133 return provider_->GetFileContents(filename, file_contents);
136 void OSExchangeData::SetDownloadFileInfo(const DownloadFileInfo& download) {
137 provider_->SetDownloadFileInfo(download);
139 #endif
141 #if defined(USE_AURA)
142 void OSExchangeData::SetHtml(const base::string16& html, const GURL& base_url) {
143 provider_->SetHtml(html, base_url);
146 bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const {
147 return provider_->GetHtml(html, base_url);
149 #endif
151 } // namespace ui